package com.bdqn.tour.dao.impl;

import com.bdqn.tour.dao.BaseDao;
import com.bdqn.tour.dao.HqfAddScenicDao;
import com.bdqn.tour.pojo.Scenic;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class HqfAddScenicDaoImpl extends BaseDao implements HqfAddScenicDao {
    @Override
    //添加景点信息数据
    public int addScenic(Scenic scenic) {
      int count = 0;
      //获取连接对象 Connection
      Connection conn = this.getConnection();
      // 初始化PreparedStatement对象
      PreparedStatement psmt = null;
      //编写sql语句添加景点数据
        String sql = "insert into scenictable(scenic_name,scenic_address,price,img,satisfaction,city,html) values(?,?,?,?,?,?,?)";
        try {
            //创建预编译对象
            psmt = conn.prepareStatement(sql);
            psmt.setString(1,scenic.getScenic_name());
            psmt.setString(2,scenic.getScenic_address());
            psmt.setInt(3,scenic.getPrice());
            psmt.setString(4,scenic.getImg());
            psmt.setInt(5,scenic.getSatisfaction());
            psmt.setString(6,scenic.getCity());
            psmt.setString(7,scenic.getHtml());
            //执行sql语句
           count = psmt.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //关闭连接
            closeAll(conn,psmt,null);
        }
        //返回结果
        return count;
    }
}
